{__NOLAYOUT__}
<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<!--suppress ALL -->
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="favicon.ico" >
    <link rel="Shortcut Icon" href="favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/static/admin/lib/html5.js"></script>
    <script type="text/javascript" src="/static/admin/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/static/admin/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/static/admin/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/static/admin/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/static/admin/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="/static/admin/static/h-ui.admin/css/style.css" />
    <link rel="stylesheet" type="text/css" href="/static/admin/lib/layui/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="/static/admin/lib/icheck/icheck.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script><![endif]-->
    <!--/meta 作为公共模版分离出去-->

    <link href="/static/admin/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="page-container">
    <form action="{:url('doadd')}" method="post" class="form form-horizontal" id="form-article-add" enctype="multipart/form-data">
        {:token('__token__', 'sha1')}
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>产品标题：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="" name="goods_name">
            </div>
        </div>
        <div class="row cl" id="section">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>分类->品牌：</label>
            <div class="formControls col-xs-8 col-sm-9 layui-input-inline" style="width: 20%"> <span class="select-box">
				<strong class="border  ">顶级栏目</strong>
                <div class="line mt-10"></div>
                <select name="goods_class_top" id="top_section" class="select" lay-verify="required" lay-search="" >
					<option value="">--请选择--</option>
				</select>
				</span>
            </div>
            <div class="formControls col-xs-8 col-sm-9" style="width: 20%">
                <span class="select-box">
                    <strong class="border text-c">次级栏目</strong>
                    <div class="line mt-10"></div>
                    <select name="goods_class_sec" class="select" id="sec_section">
                        <option value="">&#45;&#45;请选择&#45;&#45;</option>
                    </select>
				</span>
            </div>
            <div class="formControls col-xs-8 col-sm-9" style="width: 20%">
                <span class="select-box">
                    <strong class="border text-c">品牌栏目</strong>
                    <div class="line mt-10"></div>
                    <select name="goods_brand" class="select" id="choose_brand">
                        <option value="">--请选择--</option>
                    </select>
				</span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>排序值：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="0" placeholder="" id="" name="goods_order">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>产品状态：</label>
            <div class=" skin-minimal formControls col-xs-8 col-sm-9">
                <div class="radio-box">
                    <input type="radio" id="radio-1" name="goods_status" value="0" checked>
                    <label for="radio-1">上架</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="radio-2" name="goods_status" value="1">
                    <label for="radio-2">下架</label>
                </div>
            </div>
        </div>
        <!--<div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>商品品牌：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" name="goods_brand" id="" placeholder="" value="" class="input-text">
            </div>
        </div>-->
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>商品型号分类：</label>
            <div class=" skin-minimal formControls col-xs-8 col-sm-9">
                <div class="check-box">
                    <input type="checkbox" id="checkbox-1" name="goods_model[]" value="1">
                    <label for="checkbox-1">50分H色</label >
                </div>
                <div class="check-box">
                    <input type="checkbox" id="checkbox-2" name="goods_model[]" value="2">
                    <label for="checkbox-2">70分H色</label >
                </div>
                <div class="check-box">
                    <input type="checkbox" id="checkbox-3" name="goods_model[]" value="3">
                    <label for="checkbox-3">100分D色</label >
                </div>
                <div class="check-box">
                    <input type="checkbox" id="checkbox-4" name="goods_model[]" value="4">
                    <label for="checkbox-4">100分F色</label >
                </div>
                <div class="check-box">
                    <input type="checkbox" id="checkbox-5" name="goods_model[]" value="5">
                    <label for="checkbox-5">100分H色</label >
                </div>
                <div class="check-box">
                    <input type="checkbox" id="checkbox-6" name="goods_model[]" value="6">
                    <label for="checkbox-6">200分H色</label >
                </div>
                <div class="check-box">
                    <input type="checkbox" id="checkbox-7" name="goods_model[]" value="7">
                    <label for="checkbox-7">300分D色</label >
                </div>
                <div class="check-box">
                    <input type="checkbox" id="checkbox-8" name="goods_model[]" value="8">
                    <label for="checkbox-8">500分H色</label >
                </div>
                <div class="check-box">
                    <input type="checkbox" id="checkbox-9" name="goods_model[]" value="9">
                    <label for="checkbox-9">999分D色</label >
                </div>
                <div class="check-box">
                    <input type="checkbox" id="checkbox-10" name="goods_model[]" value="10">
                    <label for="checkbox-10">其他</label >
                </div>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">产品价格：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" name="goods_price" id="" placeholder="" value="" class="input-text" style="width:90%">
                元</div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">价格计算单位：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select class="select" name="goods_unit">
					<option value="1" selected>枚</option>
					<option value="2">根</option>
					<option value="3">颗</option>
				</select>
				</span> </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">产品数量：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" name="goods_num" id="" placeholder="" value="" class="input-text" style="width:90%">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">产品摘要：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea name="goods_overview" cols="" rows="" class="textarea"  placeholder="说点什么...最少输入10个字符" datatype="*10-100" dragonfly="true" nullmsg="备注不能为空！" onKeyUp="textarealength(this,200)"></textarea>
                <p class="textarea-numberbar"><em class="textarea-length">0</em>/200</p>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">缩略图：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="uploader-thum-container">
                    <div id="fileList" class="uploader-list"></div>
                    <div id="upload" class=" btn btn-primary radius">
                        选择图片
                    </div>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="demo1" width="200px">
                        <p id="demoText"></p>
                    </div>
                    <input type="text" value="" name="goods_pic" class="input-text" placeholder="图片保存路径">
                </div>
            </div>
        </div>

        <!--<div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">详情图片：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <button type="button" class="btn btn-primary radius" id="uploads">多图片上传</button>
                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                    预览图：
                    <div class="layui-upload-list" id="demo2" width="200px"></div>
                </blockquote>
                <input type="text" value="" name="goods_other_pic" class="input-text" disabled placeholder="图片保存路径">
            </div>
        </div>-->
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">详细内容：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <script id="editor" type="text/plain" style="width:100%;height:400px;" name="goods_introduce"></script></div>
        </div>
                <div class="row cl">
                    <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                    <button onClick="article_save_submit();" class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存并提交审核</button>
                <button onClick="article_save();" class="btn btn-secondary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存草稿</button>
                <button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
                    </div>
                </div>
    </form>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/static/admin/lib/jquery/1.9.1/jquery.min.js"></script><script type="text/javascript" src="/static/admin/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/static/admin/static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="/static/admin/static/h-ui.admin/js/H-ui.admin.page.js"></script>
<!--/_footer /作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="/static/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="/static/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="/static/admin/lib/webuploader/0.1.5/webuploader.min.js"></script>
<script type="text/javascript" src="/static/admin/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="/static/admin/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="/static/admin/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/static/admin/lib/layui/layui.js"></script>
<script type="text/javascript" src="/static/admin/lib/icheck/jquery.icheck.min.js"></script>
<script type="text/javascript">
    //栏目和商品的下拉选项
    //直接先去获取内容，然后把内容插进去
    $.ajax({
        'type':'get',
        'data':{pid:0},
        'async':true,
        'url':'{:url(\'Top_section\')}',
        'dataType':'json',
        success:
            function(data){
                console.log(data);
                //将得到的结果拼接到select里面
                for(var i=0;i<data.length;i++){
                    level=data[i]['level'];
                    name=data[i]['catname'];
                    option='<option value="'+data[i]['id']+'">'+name+'</option>';
                    //拼接进入
                    $('#top_section').append(option);
                }
            },

        //发送失败会出现
        error:
            function(){
                alert('Ajax 响应失败');
            }
    });
    //次级栏目的选择,增加选择顶级栏目同时出现品牌
    $(document).on('change',"#top_section",function(){
        pid=$(this).val();
        o=$(this);
        //删除子元素
        $("#sec_section").empty();

        $("#choose_brand").empty();
        $.ajax({
            'type':'get',
            'data':{pid:pid},
            'async':true,
            'url':'{:url(\'Top_section\')}',
            'dataType':'json',
            success:
                function(data){
//                    console.log(data);
                    //将得到的结果拼接到select里面
                    select=$("#sec_section");
//                    select.append('<option value="">--请选择--</option>');
                    for(var i=0;i<data.length;i++){
                        option='<option value="'+data[i]['id']+'">'+data[i]['catname']+'</option> ';
                        //拼接进入
                        select.append(option);
                    }
                },
            //发送失败会出现
            error:
                function(){
                    alert('Ajax 响应失败');
                }
        });
//        cid=$(this).val();
        $.ajax({
            'type':'get',
            'data':{cid:pid},
            'async':true,
            'url':'{:url(\'Choose_brand\')}',
            'dataType':'json',
            success:
                function(data){
                    //将得到的结果拼接到select里面
                    select=$("#choose_brand");
                    for(var i=0;i<data.length;i++){
                        option='<option value="'+data[i]['id']+'">'+data[i]['brand_name']+'</option> ';
                        //拼接进入
                        select.append(option);
                    }
                },
            //发送失败会出现
            error:
                function(){
                    alert('Ajax 响应失败');
                }
        });
    });
    //进行商品的选择
    $(document).on('change',"#sec_section",function(){
        cid=$(this).val();
        o=$(this);
        //删除子元素
        $("#choose_brand").empty();
        $.ajax({
            'type':'get',
            'data':{cid:cid},
            'async':true,
            'url':'{:url(\'Choose_brand\')}',
            'dataType':'json',
            success:
                function(data){
                    //将得到的结果拼接到select里面
                    select=$("#choose_brand");
                    for(var i=0;i<data.length;i++){
                        option='<option value="'+data[i]['id']+'">'+data[i]['brand_name']+'</option> ';
                        //拼接进入
                        select.append(option);
                    }
                },
            //发送失败会出现
            error:
                function(){
                    alert('Ajax 响应失败');
                }
        });
    });
    $(function() {
        $('.skin-minimal input').iCheck({
                            checkboxClass: 'icheckbox-blue',
                            radioClass: 'iradio-blue',
                            increaseArea: '20%'
        });
        //进行基本的validate的验证
        $("#form-article-add").validate({
            rules:{
                goods_name:{
                    required:true,
                },
                goods_brand:{
                    required:true,
                },
                goods_price:{
                    required:true,
                    number:true,
                },
                goods_num:{
                    required:true,
                    number:true,
                },
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form) {
                //进行验证成功后的提交
                $(form).ajaxSubmit({
                    type: 'post',
                    dataType: "json",
                    url: '{:url("doadd")}',
                    success: function (data) {
                        //alert(data.msg);
                        if (data.status == 0){
                            layer.msg(data.msg, {icon: 6,time:1000}, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload(); //刷新父页面
                                parent.layer.close(index);
                            });
                        }else{
                            layer.msg(data.msg, {icon: 5});
                        }
                    },
                    error: function (XmlHttpRequest, textStatus, errorThrown) {
                    }
                });
            }
        });

        //进行数据的后台提交
        layui.use('form', function() {
            var form = layui.form;

        });
            //layui的图片上传
        layui.use('upload', function () {
            var upload = layui.upload;
                            //执行实例
            var uploadInst = upload.render({
                elem: '#upload' //绑定元素
                , url: '{:url("pics")}' //上传接口
                , ext: 'jpg|png|gif'
                , area: ['500', '500px']
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    if (res.status == 0) {
                        layer.msg(res.msg, {icon: 2, time: 1000});
                    }
                    $('input[name=goods_pic]').val(res.path);
                    layer.msg(res.msg, {icon: 1, time: 1000});
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
            //多图片上传
            upload.render({
                elem: '#uploads'
                ,url: '{:url("goods_pic")}'
                ,multiple: true
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img" width="100px" height="100px">')
                    });
                }
                ,done: function(res){
                    if (res.status == 0) {
                        layer.msg(res.msg, {icon: 2, time: 1000});
                    }
//                    $('input[name=goods_other_pic]').append('<input type="text" name="goods_other_pic" value="'+res.path+'"');
                    $('input[name=goods_other_pic]').val(res.path);
                    layer.msg(res.msg, {icon: 1, time: 1000});
                    //上传完毕
                }
            });

        });
    });

    $(function(){
      var ue = UE.getEditor('editor');
            });
    $('.layui-layer-setwin').click(function(){
        alert("获取到了页面要关闭的事件了！");
    });
</script>
</body>
</html>